home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
c01oop.zip
/
CPPWKBK
/
CPPV4-1.H
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-25
|
2KB
|
63 lines
// CPPV4-1.H by Rick Conn Using Borland C++
#ifndef COMPLEX_H_
#define COMPLEX_H_
// COMPLEX Class
class complex {
float real_part;
float imag_part;
char *name;
public:
complex (char *, float rp=0.0, float ip=0.0);
void set (float rp=0.0, float ip=0.0);
complex & operator= (complex &);
complex operator+ (complex &right);
complex operator- (complex &right);
complex operator* (complex &right);
void print(void);
};
complex::complex (char *n, float rp, float ip) {
name = n; real_part = rp; imag_part = ip;
}
void complex::set (float rp, float ip) {
real_part = rp; imag_part = ip;
}
complex & complex::operator= (complex &arg) {
real_part = arg.real_part;
imag_part = arg.imag_part;
return *this;
}
complex complex::operator+ (complex &right) {
complex result ("Temp");
result.real_part = real_part + right.real_part;
result.imag_part = imag_part + right.imag_part;
return result;
}
complex complex::operator- (complex &right) {
complex result ("Temp");
result.real_part = real_part - right.real_part;
result.imag_part = imag_part - right.imag_part;
return result;
}
complex complex::operator* (complex &right) {
complex result ("Temp");
result.real_part = real_part * right.real_part -
imag_part * right.imag_part;
result.imag_part = imag_part * right.real_part +
real_part * right.imag_part;
return result;
}
void complex::print(void) {
printf(" %s: %10.5f + %10.5fi\n",
name, real_part, imag_part);
}
#endif // COMPLEX_H_